﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using PlanningGIS.Framework;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
////using ESRI.ArcGIS.TOCControl;

namespace PlanningGIS.TocContextMenu.Button
{
    /// <summary>
    /// 作用：新建图层组
    /// 作者：
    /// 编写日期：2009-03-25
    /// </summary>
    internal class NewGroupLayer : BaseCommand
    {
        IApplication m_Application = null;
        public NewGroupLayer()
        {
            base.m_caption = "新建图层组";
            base.m_toolTip = base.Caption;
        }
        
        public override void OnCreate(object hook)
        {
            m_Application = hook as IApplication;
        }

        public override void OnClick()
        {
            if ((m_Application as IFramework).TOCControl.CustomProperty is IMap)
            {
                IMap pMap = (m_Application as IFramework).TOCControl.CustomProperty as IMap;
                IGroupLayer pGroupLyr = new GroupLayerClass();
                pGroupLyr.Name = "图层组";
                pMap.AddLayer(pGroupLyr);
                (m_Application as IFramework).TOCControl.Update();
            }
            else if ((m_Application as IFramework).TOCControl.CustomProperty is IGroupLayer)
            {
                IGroupLayer pLayer = (m_Application as IFramework).TOCControl.CustomProperty as IGroupLayer;
                IGroupLayer pGroupLyr = new GroupLayerClass();
                pGroupLyr.Name = "图层组";
                pLayer.Add(pGroupLyr);
                (m_Application as IFramework).TOCControl.Update();
            }

        }
        public override bool Enabled
        {
            get
            {
                return ((m_Application as IFramework).IsMapCtrlactive && ((m_Application as IFramework).TOCControl.CustomProperty is IGroupLayer || (m_Application as IFramework).TOCControl.CustomProperty is IMap)) ? true : false;
            }
        }
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.TocContextMenu.Res." + this.GetType().Name + ".ico";
                System.IO.Stream stream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (stream == null) return 0;

                return new Bitmap(stream).GetHbitmap().ToInt32();
            }
        }
    }
}